﻿using System;

namespace 多播委托
{
    class Program
    {
        static void Main(string[] args)
        {
            //注意点：Func会返回最后一个注册的方法
            Func<string> a = A;
            //输出委托内部的注册方法
            Delegate[] d = a.GetInvocationList();
            foreach (Delegate item in d)
            {
                Console.WriteLine(item.Method);
                //输出当前遍历的委托中的注册方法
                Console.WriteLine(item.DynamicInvoke(null));
            }
            //属于增加注册方法
            a +=B;
            a += C;
            //删减注册方法
            //a -= C;
            Console.WriteLine(a());

            Action<string,bool> a1 = D;
            //增加注册方法
            a1 += E;
            a1 += F;
          
            //删减注册方法
            //a1 -= E;
            //a1 -= F;
            a1("我爱你", true);
            //输出委托内部的注册方法
            Delegate[] w = a1.GetInvocationList();
            object[] obj = new object[] { "我爱你", true };
            foreach (Delegate item in w)
            {
                Console.WriteLine(item.Method);
                Console.WriteLine(item.DynamicInvoke(obj));
            }

        }
        public static string A()
        {
            Console.WriteLine("-------");
            return "10";
        }
        public static string B()
        {
            Console.WriteLine("+++++++");
            return "20";
        }
        public static string C()
        {
            Console.WriteLine("**********");
            return "30";
        }
        public static void D(string a,bool b)
        {
            Console.WriteLine("D"+a+b);
        }
        public static void E(string a, bool b)
        {
            Console.WriteLine("E" + a + b);
        }
        public static void F(string a, bool b)
        {
            Console.WriteLine("F" + a + b);
        }
    }
}
